//
//  CZBaseTableViewController.swift
//  sinaSwifWeiBo
//
//  Created by 张雪雪 on 16/2/25.
//  Copyright © 2016年 张雪雪. All rights reserved.
//

import UIKit


class CZBaseTableViewController: UITableViewController , CZVisitorDelegate {
    
    var visitor :CZVisitor?
    
    var isLogin: Bool = CZUserViewModel.shareInstance.isLogin!
//    lazy var model : CZUserModel? = CZUserModel.readObject("infoo.plist")
//    
   // var isLogin : Bool = true //一会可以去判断
   
    override func loadView() {
        
        //let model = CZUserModel.readObject("infoo.plist")
        
        
        if CZUserViewModel.shareInstance.isLogin!{
        
        super.loadView()
       
        }else{
        
        showVisitorView()
        
        }
    }
    
    
    
    
    //viewDidLoad走一次
    override func viewDidLoad() {
        
        super.viewDidLoad()
        
        
    }
    
    //显示访客视图
    private func showVisitorView(){
    
    visitor = CZVisitor()
        
        /**
   
        OC里设置完代理,不去遵守并实现代理方法不会报错
        Swift会报错,遵守并实现代理方法

        */
    visitor?.delegate = self
        
        view = visitor
        
        //设置nav 
        
        setupNav()

    }
    
    
    
    //设置NAV的
    private func setupNav(){

        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action:
            "didRegister")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "didLogin")
    }
    
    func didLogin(){

        print("登陆成")
    
    }

    func didRegister() {
        
//        print("控制器 代理回调")
        
        let login = CZLoginViewController()
        
        let nav = UINavigationController(rootViewController: login)

        
        //显示控制器

        presentViewController(nav, animated: true ) { () -> Void in
           print("创建控制器成功")
        }

    }
 

}
